package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo3 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
            Person  p =new Person("张三",22);
        System.out.println(p);

        //1：获取类对象
        Class cls= Class.forName("reflect.Person");
        //2:通过类对象获取指定的构造器
        Constructor c =cls.getConstructor(String.class,int.class);
        //3:通过该构造器实例化对象
        Object o =c.newInstance("李四",32);
        System.out.println(o);

    }
}
